package com.bigData.main.service.impl;

import com.bigData.main.mapper.UserRegisterMapper;
import com.bigData.main.pojo.UserInfo;
import com.bigData.main.service.UserRegisterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserRegisterServicelmpl implements UserRegisterService {

    @Resource
    UserRegisterMapper userRegisterMapper;

    public Integer insertUserInfo(UserInfo u) {
        return userRegisterMapper.insertUser(u);
    }


    public Integer updateUserInfo(UserInfo u) {
        return userRegisterMapper.updateUser(u);
    }

//    public Integer updateRootInfo(userinfo u){
//        return umap.updateRoot(u);
//    }

    public Integer deleteUserInfo(UserInfo u) {
        return userRegisterMapper.deleteUser(u);
    }

    public Integer getUserName(UserInfo u) {

        //调用根据用户名查密码
        UserInfo user = userRegisterMapper.getUserName(u);
        //保存返回值
        int re = 0;
        if (user != null) {
            re = 2;
            //用户存在不可以注册

        } else {
            //可以注册
            u.setUid(System.currentTimeMillis());
            re = userRegisterMapper.insertUser(u);
        }
        return re;
    }

    public Integer insertRootInfo(UserInfo u) {
        return userRegisterMapper.insertRoot(u);
    }


    public Integer getRootName(UserInfo u) {

        //调用根据用户名查密码
        UserInfo user = userRegisterMapper.getRootName(u);
        //保存返回值
        int re = 0;
        if (user != null) {
            re = 2;
            //用户存在不可以注册

        } else {
            //可以注册
            re = userRegisterMapper.insertRoot(u);
        }
        return re;
    }

    public List<UserInfo> user() {
        return userRegisterMapper.user();
    }

    @Override
    public Integer uroot(UserInfo u) {
        return userRegisterMapper.uroot(u);
    }

}
